package ws.jdbc.concurrent.driver.sqlserver.tds

import ws.utils.ArrayUtil
import ws.utils.io.LittleEndianDataInputStream
import static ws.jdbc.concurrent.driver.sqlserver.tds.TDSMessage.*
import static ws.jdbc.concurrent.driver.sqlserver.Login.*

/**
 * Test of the TDSMessage class login request.
 * 
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
class TDSMessageLoginTest extends GroovyTestCase {
  
  void setUp() {
    println "-----------------------------------------------------------------"
  }

  void testLogin() {
    println "testLogin()\n"

    TDSMessage message = new TDSMessage(new Socket(serverName, port))
    assertTrue message.login("", userName, password, serverName, "PerformanceTest")
    message = new TDSMessage(new Socket(serverName, port))
    assertFalse message.login("", userName, "sdf", serverName, "PerformanceTest")
    message = new TDSMessage(new Socket(serverName, port))
    assertFalse message.login("", "JohnDoe", password, serverName, "PerformanceTest")
  }

  void testLoginTokens() {
    println "testLoginTokens()\n"

    TDSMessage message = new TDSMessage(new Socket(serverName, port))
    message.sendLoginRequest("", userName, password, serverName, "PerformanceTest")
    message.readResponseHeader()

    def collection = TokenReader.readTokens(new LittleEndianDataInputStream(message.is), message.length - 8)
    println collection
  }
}